package game.msgame.entity;

import java.net.DatagramSocket;
import java.util.Objects;

/**
 * 用户类
 *
 * @author Mr.Alpaca
 * @version 1.0.0
 */
public class User {
    /**
     * 用户账号
     */
    private Long id;
    /**
     * 密码
     */
    private String password;
    /**
     * 用户名
     */
    private String name;
    /**
     * 用于接收消息的套接字
     */
    private DatagramSocket socket;
    /**
     * 为true时表示用户在线,false表示用户离线
     */
    private boolean onlineFlag;

    public User(Long id, String password, String name, DatagramSocket socket) {
        this.id = id;
        this.password = password;
        this.name = name;
        this.socket = socket;
        this.onlineFlag = false;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public DatagramSocket getSocket() {
        return socket;
    }

    public void setSocket(DatagramSocket socket) {
        this.socket = socket;
    }

    public boolean isOnlineFlag() {
        return onlineFlag;
    }

    public void setOnlineFlag(boolean onlineFlag) {
        this.onlineFlag = onlineFlag;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof User)) {
            return false;
        }
        User user = (User) o;
        return onlineFlag == user.onlineFlag &&
                Objects.equals(id, user.id) &&
                Objects.equals(password, user.password) &&
                Objects.equals(socket, user.socket);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, password, socket, onlineFlag);
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", password='" + password + '\'' +
                ", name='" + name + '\'' +
                ", socket=" + socket +
                ", onlineFlag=" + onlineFlag +
                '}';
    }
}
